package databaseVersionControl.gui;

import java.awt.BorderLayout;
import java.awt.TextArea;
import java.io.ByteArrayOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;

import javax.swing.JFrame;

import org.apache.log4j.Logger;

public class Transcript extends JFrame {

	private static final long serialVersionUID = 1L;
	private static final Integer WIDTH = 700;
	private static final Integer HEIGHT = 225;
	
    private TextArea transcriptTextArea = new TextArea();
    
    private PrintStream printStream  = new PrintStream(
         new FilteredStream(
           new ByteArrayOutputStream()
         )
    );
    
    public Transcript() {
        configLayout();
        configTranscriptOutput();
        displayLog();
    }
    
    private void configLayout() {
        this.setTitle("Transcript");
        this.setSize(WIDTH, HEIGHT);
        this.setLayout(new BorderLayout());
        this.add("Center" , transcriptTextArea);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
    
    private void configTranscriptOutput() {
        System.setOut(printStream); // catches System.out messages
        System.setErr(printStream); // catches error messages
    }
    
    private void displayLog() {
        setLocationRelativeTo(null);
        setVisible(true);
        requestFocus();
    }

    private class FilteredStream extends FilterOutputStream {
        public FilteredStream(OutputStream aStream) {
            super(aStream);
        }

        public void write(byte b[]) throws IOException {
            String aString = new String(b);
            transcriptTextArea.append(aString);
        }

        public void write(byte b[], int off, int len) throws IOException {
            String aString = new String(b , off , len);
            transcriptTextArea.append(aString);
        }
    }

    public static void main(String[] args) {
    	new Transcript();
		Logger logger = Logger.getLogger(Transcript.class);
		
		for (int i=0; i < 1000; i++) logger.info("CREATE SEQUENCE SVC_SEQUENCE");
	}

}